package com.ruoyi.app.controller;

import com.ruoyi.app.service.BaiDuAiService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.translate.domain.FIleSVo;
import com.ruoyi.translate.domain.ShiBieVo;
import com.ruoyi.translate.domain.Words;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

import static com.ruoyi.translate.utils.TranslateUtil.shiBie;

/**
 * 百度ai翻译
 *
 * @ClassName: BaiDuAiController
 * @Author: chenJie
 * @Description: 百度ai翻译
 */
@RestController
@RequestMapping("/api/baidu")
public class BaiDuAiController {
    @Autowired
    private BaiDuAiService baiDuAiService;


    @PostMapping("/translate")
    @Anonymous
    public AjaxResult translate(@RequestBody FIleSVo file) throws IOException {
        // 判断accessToken 是否为空
        if (StringUtils.isEmpty(file.getFileUrl())) {
            return AjaxResult.error("没有文件名");
        }
        // 识别
        List<Words> input = shiBie(file.getFileUrl());

        if (input.isEmpty()) {
            return AjaxResult.error(6000,"图片中没有任何的文字，请重新上传");
        }
        AjaxResult newList = baiDuAiService.getNewList(input,file.getUserId());

        return newList;
    }


}
